/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-08-02
 * Time: 17:04
 */
public class Test {
    public static MySingleList.ListNode getIntersectionNode(MySingleList.ListNode headA,
                                                            MySingleList.ListNode headB){
        int l1=0;
        int l2=0;
        MySingleList.ListNode aa=headA;
        MySingleList.ListNode bb=headB;

        while(aa!=null){
            l1++;
            aa=aa.next;
        }
        while(bb!=null){
            l2++;
            bb=bb.next;
        }

        aa=headA;
        bb=headB;
        int len=l1-l2;
        int count=0;
        if(len<0){
            while(count!=len){
                bb=bb.next;
                count++;
            }
        }else if(len>0){
            while(count!=len){
                aa=aa.next;
                count++;
            }
        }

        while (aa!=bb){
            aa=aa.next;
            bb=bb.next;
        }

        if(aa==null||bb==null){
            return null;
        }

        return aa;

    }
    public static MySingleList.ListNode merge(MySingleList.ListNode headA,
                                       MySingleList.ListNode headB){
        MySingleList.ListNode newHead = new MySingleList.ListNode(-1);
        MySingleList.ListNode tmp = newHead;
        //遍历这2个链表
        while (headA != null && headB != null) {
            if(headA.val < headB.val) {
                tmp.next = headA;
                headA = headA.next;
                tmp = tmp.next;
            }else {
                tmp.next = headB;
                headB = headB.next;
                tmp = tmp.next;
            }
        }
        if(headA != null) {
            tmp.next = headA;
        }
        if(headB != null) {
            tmp.next = headB;
        }

        return newHead.next;
    }

    public static void main(String[] args) {
        MySingleList list = new MySingleList();
        list.addFirst(41);
        list.addFirst(23);
        list.addFirst(11);
        list.addFirst(23);
        list.addFirst(31);


//        MySingleList list2 = new MySingleList();
//        list2.addFirst(56);
//        list2.addFirst(45);
//        list2.addFirst(34);
//        list2.addFirst(23);
//        list2.addFirst(12);
//        //只能升序的链表
//        MySingleList.ListNode newH = merge(list.head,list2.head);
//
//        list.display2(newH);

//        list.removeAllKey(31);
//        list.display();

        boolean ret=list.chkPalindrome();
        System.out.println(ret);

    }

}




